package lab4p3;

import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

class NumberComboBoxModel extends AbstractListModel<Integer> implements ComboBoxModel<Integer> {
	/**
	 * Data members
	 */
	private static final long serialVersionUID = 1L;
	private String selectedItem;
	private List<Integer> numbers;

	/**
	 * Constructor 
	 * 
	 * @param min
	 * @param max
	 */
	public NumberComboBoxModel(int min, int max){
		numbers = new ArrayList<Integer>();
		for (int i=min; i<=max; i++)
			numbers.add( i );
	}
	
	/**
	 * getSize
	 * 
	 * Required by ComboBoxModel
	 * 
	 */
	public int getSize() {
		return numbers.size();
	}

	/**
	 * getElementAt
	 * 
	 * Required by ComboBoxModel
	 * 
	 */
	public Integer getElementAt(int index) {
		return numbers.get(index);
	}

	/**
	 * setSelectedItem
	 * 
	 * Required by ComboBoxModel
	 * 
	 */
	public void setSelectedItem(Object anItem) {
		for (Integer i : numbers)
			if (anItem == i){
				selectedItem = i.toString();
				break;
			}
	}

	/**
	 * getSelectedItem
	 * 
	 * Required by ComboBoxModel
	 * 
	 */
	public Object getSelectedItem() {
		return selectedItem;
	}
}